function longestVersionPrefix(versions) {
    // write code here
    let res = {};

    let result = [];
    let arr = versions;
    arr.forEach(e => {
        //1.存入
        if (!res[e]) {
            res[e] = 0; //设置子数
        }
    });
    arr.forEach(e => {
        //2.判断是否有子
        let strs = e.split('.');
        for (let i = 0; i < strs.length; i++) {
            const element = strs[i];
            //1.存入
            if (!res[element]) {
                res[element] = 0; //设置子数
            }

        }
        strs.splice(strs.length - 1, 1)

        let pPath = strs.join('.');
        if (res.hasOwnProperty(pPath)) {
            res[pPath]++; //增加数量
        }
    })
    console.log('res', res);
    for (const k in res) {
        if (res.hasOwnProperty(k) && res[k] > 0) {
            result.push(k);
        }
    }
    if (result.length == 0) {
        return '';
    }
    return result.join(',');
}

console.log(longestVersionPrefix(["2.3.4", "2.3.4.1", "2.2.2"]));